import request from '@/utils/request'

// 显示库区列表
export function getAreaList() {
  return request({
    url: '/area/list'
  })
}

// 分页查询库区
export function areaListPage(params) {
  return request({
    url: '/area/page',
    params
  })
}

// 分页查询库区详细
export function areaDetailPage(page, search) {
  // ''
  if (!search) {
    return request({
      url: '/area/pageDetail',
      params: page
    })
  } else {
    const [warehouseName, name, status] = search
    const obj = { status }
    // ""
    if (name) obj.name = name
    if (warehouseName) obj.warehouseName = warehouseName
    return request({
      url: '/area/pageDetail',
      params: {
        ...page, ...obj
      }
    })
  }
}

// 新增库区
export function setAreaList(data) {
  return request({
    url: '/area',
    method: 'post',
    data
  })
}

// 获取code
export function getCode() {
  return request({
    url: '/codeFactory/next/KQ'
  })
}

// 获取仓库列表
export function getwarehouseList(status) {
  return request({
    url: `/warehouse/list?status=${status}`
  })
}

// 回显库区
export function bckAreaList(params) {
  return request({
    url: `/area/${params}`
  })
}

// 保存修改
export function updataAreaList(data) {
  return request({
    url: '/area',
    method: 'put',
    data
  })
}

// 删除
export function deleteAreaList(params) {
  return request({
    url: '/area',
    method: 'delete',
    params
  })
}

// upload
export function importArea(data) {
  return request({
    headers: {
      'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryMsmAiJBHBpQ0L7D9',
      'x-ext': '.xlsx'
    },
    url: '/area/importExcel',
    method: 'post',
    data
  })
}

